package com.lv.LvRefundRecord.dao;
import com.aqgj.util.BaseDaoImpl;
import com.lv.LvRefundRecord.bean.LvRefundRecord;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 *
 * @author 
 * @date
 */
@Repository("LvRefundRecordDao")
public class LvRefundRecordDao extends BaseDaoImpl<LvRefundRecord> {

    /**
     * 获取退款记录列表
     * @param pageNo  页码
     * @param pageSize 条数
     * @param cid   公司ID
     * @return
     */
    public List getRecordList(int pageNo, int pageSize, String cid) {
        String sql = "SELECT t.id,CONCAT_WS('-',o.start_site_name,o.terminal_site_name) name,t.type,o.order_number,o.order_balance,t.money,t.add_time " +
                    " FROM lv_refund_record t " +
                    " INNER JOIN lv_tourism_order o ON t.fk_lv_order_id = o.id " +
                    " WHERE o.fk_transport_id='" + cid + "'";
        sql+=" order by t.add_time desc";
        return this.listSqlPagQuery(sql, pageNo, pageSize);
    }

    /**
     * 获取总条数
     * @param cid  公司ID
     * @return
     */
    public  Integer getSqlSumQuery(String cid){
        String sql = " SELECT r.id,CONCAT_WS('-',o.start_site_name,o.terminal_site_name) name,r.type,o.order_number,o.order_balance,r.money,r.add_time " +
                    "FROM lv_refund_record r " +
                    "INNER JOIN lv_tourism_order o ON r.fk_lv_order_id = o.id " +
                    "WHERE o.fk_transport_id='" + cid + "'";
        return  this.getSqlSumQuery(sql);
    }

    /**
     * 退款记录详情.
     * @param rid  退款记录ID
     * @return
     */
    public Object[] getRecordInfo(String rid) {
        String sql="SELECT concat_ws('-',o.start_site_name,o.terminal_site_name) name,r.type,o.order_number,o.order_balance,o.pay_balance,o.pay_mode,o.order_time,r.money,r.add_time " +
                    ",o.tourism_for_sale_server_date, IFNULL(u.account,a.name) personnel " +
                    "FROM lv_refund_record r " +
                    "INNER JOIN lv_tourism_order o ON r.fk_lv_order_id = o.id " +
                    "LEFT JOIN sys_user u ON r.fk_manager_id=u.id " +
                    "LEFT JOIN app_user a ON r.fk_manager_id=a.id " +
                    "WHERE r.id='"+rid+"'";
        return (Object[]) this.createSQLQuery(sql).getResultList().get(0);
    }
}